import requests
import os
import sys
from lxml import etree

cwd = os.getcwd()
sys.path.append(cwd)
from pub_func import DownloadFile, folder_exist

base_url = 'http://192.168.70.41:5233/'
headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
}

response = requests.get(base_url, headers)
html = etree.HTML(response.text)
file_list = html.xpath('/html/body/pre/a/@href')


for file_name in file_list:
    # 判断是否由.txt结尾
    if file_name.endswith('.txt'):
        url = os.path.join(base_url, file_name)
        time_str = file_name[:4] + file_name[5:7] + file_name[8:10]
        dir_name = os.path.join('./70/', time_str)
        folder_exist(dir_name)
        DownloadFile(url, dir_name, file_name)
    
